package com.sxdt.Dao.imp;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Repository;

import com.sxdt.Dao.UserOperation;
import com.sxdt.model.User;

/**
 * 功能：用户的注册与管理
 * @author 刘佳伟
 *
 */
@Repository("userImp")
public class UserDaoImp implements UserOperation{
	
	SqlSessionTemplate sst;
	
	@Resource(name="sqlSessionTemplate")
	public void setSst(SqlSessionTemplate sst) {
		this.sst = sst;
	}

	/**
	 * 功能：向数据库插入一条user数据
	 */
	public int insertUser(User u) {
		
		//返回插入数据的行数，用来判断成功或失败
		int i = 0;
		
		UserOperation userOperation = sst.getMapper(UserOperation.class);
		
		i = userOperation.insertUser(u);
		
		return i;
		
	}
	
	/**
	 * 功能：完善数据库中的用户信息
	 */
	public int insertUserMore(User u) {
		
		int i = 0;
		
		UserOperation userOperation = sst.getMapper(UserOperation.class);
		
		i = userOperation.insertUserMore(u);
		
		return i;
	}
	
	/**
	 * 功能：检索用户详细信息
	 */
	public User selectUserMore(int id){
		
		User u = null;
		
		UserOperation userOperation = sst.getMapper(UserOperation.class);
		
		u = userOperation.selectUserMore(id);
		
		return u;
	}
	
	/**
	 * 功能：登陆验证
	 */
	public User loginYz(User u){
		
		User user = null;
		
		UserOperation userOperation = sst.getMapper(UserOperation.class);
		
		user = userOperation.loginYz(u);
		
		return user;
	}
	
//	ClassPathXmlApplicationContext c = new ClassPathXmlApplicationContext("spring/applicationContext.xml");
//	sst = (SqlSessionTemplate) c.getBean("sqlSessionTemplate");
	
}
